<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page import="java.sql.*;"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	String name = request.getParameter("bookname");
	try {
		Class.forName("com.mysql.jdbc.Driver");
	} catch (ClassNotFoundException e) {
		out.print(e);
	}

	Connection con;
	Statement sql;
	ResultSet rs;

	String url = "jdbc:mysql://localhost:3306/bookinfo?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull";
	String user = "root";
	String psword = "chuichuiqqt";

	try { 
		String sqlcommand = "";
		if( name != null )
			if( name.equals("") )
				sqlcommand = "select * from book";
			else
				sqlcommand = "select * from book where name='" + name + "'";
		else 
			sqlcommand = "select * from book";
		con=DriverManager.getConnection(url,user,psword);
        sql=con.createStatement();
	    rs=sql.executeQuery(sqlcommand);
%>
		<table class="table">
			<tr>
				<th>书名</th>
				<th>作者</th>
				<th>出版社</th>
				<th>价钱</th>
				<th>操作</th>
			</tr>
<%
	    while(rs.next()) {
%>
				<tr>
					<td><%=rs.getString("name")%></td>
					<td><%=rs.getString("author")%></td>
					<td><%=rs.getString("publisher")%></td>
					<td><%=rs.getString("price")%></td>
					<td>
						<a class="btn btn-xs btn-default" href="book-edit.jsp?num=<%=rs.getString("num")%>">编辑</a>
					</td>
				</tr>
<%
		}
%>
			</table>
<%
	} catch(SQLException e) { 
		out.print(e);
	}
%>